/**
 * @单位名称：飞羽个人
 * 	Copyright (c) 2017 All Rights Reserved.
 * @系统名称：测试
 * @工程名称：
 * @文件名称: 
 * @类路径: 
 */
package com.feiyu.service.impl;

import com.feiyu.bean.HouseUnit;
import com.feiyu.bean.HouseUnitChange;
import com.feiyu.common.util.BeanConvertUtil;
import com.feiyu.common.util.CustomExcelUtil;
import com.feiyu.dao.HouseUnitChangeMapper;
import com.feiyu.service.HouseUnitChangeService;
import com.feiyu.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 
 * 
 * @see
 * @author 	nanshouxiao
 * @date	2018-5-23 10:19:29
 * @version	V1.0.0
 */
@Service("houseUnitChangeServiceImpl")
public class HouseUnitChangeServiceImpl extends BaseServiceImpl<HouseUnitChange, Integer> implements HouseUnitChangeService
{

    @Autowired
    private HouseUnitChangeMapper houseUnitChangeMapper;

    @Override
    public void importAllInfoByFileDir(String filePath) {
        File fileDir = new File(filePath);
        File[] files = fileDir.listFiles();
        List<HouseUnitChange> finalUnitChangeList = new ArrayList<>();
        Arrays.stream(files).forEach(file -> {
            List<HouseUnit> unitList = CustomExcelUtil.handleUnitExcel(file);
            unitList.stream().map(BeanConvertUtil::unitToChange)
                    .forEach(unitChange -> {
                        unitChange.setFileName(file.getName());
                        finalUnitChangeList.add(unitChange);
                    });

        });
        houseUnitChangeMapper.batchSaveEntity(finalUnitChangeList);
    }
}